<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Menu_manag extends CI_Controller {

    /**
     *   网站后台
     *   王超伟
     * 	 2012.09.25
     * 	 art2006art#gmail.com
     */
    public function __construct() {
        parent::__construct();
        $this->load->helper('url');
        $this->load->helper('file');
        $this->load->helper('form');
        $this->load->helper('func');
        $this->load->database();
        $this->load->model('menu_process');
        $this->config->load('menu_setting');
        $this->load->library('file_upload'); //引入类库
    }

    public function index() {
        $menu_type_array = $this->config->item('menu_name');
        $data["menu_type_array"] = $menu_type_array;
        $menu_list = $this->menu_process->menu_list();
        $data["menu_list"] = $menu_list;
        //print_r($ttt);
        $this->load->view('admin/header_view', $data);
        $this->load->view('admin/menu_view');
        $this->load->view('admin/footer_view');
    }

    public function del_menu() {
        $id = get_segment_fuc(4);
        if (isset($id)) {
            $sqldel = "delete from menu where id=\"{$id}\"";
            $this->db->query($sqldel);
        }
        redirect("admin/menu_manag");
    }

    public function add_menu() {
        $post_array = $_POST;
        $config['upload_path'] = './uploads/banner'; //设定上传存储路径
        $data = $this->file_upload->upLoadfile($config, "banner");
        //print_r($data);             
        if (isset($data)) {
            $siteurl = site_url(); //$siteurl .
            $config["source_image"] = $data["full_path"];
            $config["new_image"] = './uploads/banner/thum';
            $this->file_upload->process_img($config);
            $post_array["full_path"] = "{$data["file_name"]}";
        } else {
            $post_array["full_path"] = "";
        }
        // print_r($post_array);  exit;
        $this->menu_process->add_menu($post_array);
        redirect("admin/menu_manag");
        exit;

        //   print_r($_POST);
    }
	
	//编辑导航
	public function edit_menu() {            
            if(isset($_POST["edit_submit"])&&is_numeric($_POST["id"])){
                $this->menu_process->update_menu($_POST["id"]);
                 redirect("admin/menu_manag");
                 }         
        $id = get_segment_fuc(4);
        if (isset($id)) {
            $sqldel = "select * from menu where id=\"{$id}\"";
            $p = $this->db->query($sqldel);
	$data['row'] = $p->row_array();
        }
        $data["menu_type_array"] = $this->config->item('menu_name');
		$data["edit_type"] = 'menu';
        $this->load->view('admin/edit_view', $data);
    }

}

/* End of file admin.php */
/* Location: ./application/controllers/admin.php */